public class Test2 {
    public static void main(String[] args) {
        int[] nums = {1,2,3,4};
        rob(nums);
    }
    public static int rob (int[] nums) {
        // write code here
        int n = nums.length;
        int[] dp = new int[n + 1];
        dp[1] = nums[0];
        dp[2] = Math.max(nums[0], nums[1]);
        for(int i = 3; i <= n; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i - 1]);
        }
        return dp[n];
    }
}
